import re

import requests

base_url = r'http://172.16.22.108:8080'
url_first = base_url + '/bsams/front/login.do'
url_vericode = base_url + '/bsams/front/vericode.do'
url_info = base_url + '/bsams/front/asset/asset_list.do'
url_information = base_url + '/bsams/front/asset_user/user_info.do'
url_provider = base_url + '/bsams/front/asset_provider/asset_provider_list.do'
url_storage = base_url+'/bsams/front/asset_storage/asset_storage_list.do'
url_return_page = base_url+'/bsams/front/asset/asset_giveBack.do'
url_return = base_url+'/bsams/front/asset/asset_giveBack_save.do'
url_add = base_url+'/bsams/front/asset/asset_new.do'
url_mod = base_url+'/bsams/front/asset/asset_update.do'
url_borrow_page = base_url+'/bsams/front/asset/asset_borrow.do'
url_borrow = base_url+'/bsams/front/asset/asset_borrow_save.do'

headers = {

}
# # 1.访问首页

# resp = requests.get(url_first)
# # 返回数据
# print(resp.status_code)
# print(resp.text)

# # 2.首页验证码

# resp = requests.get(url_vericode)
# print(resp.status_code)
# # print(resp.content)

# 3.登录


id = 1
username = 'student'
password = '123456'
vericode = 'shtd'
data_login = {
    'taskId': id,
    'loginName': username,
    'password': password,
    'vericode': vericode

}
s = requests.Session()
s.get(url_first)
s.get(url_vericode)
s.post(url_first, data=data_login)

# 登陆后，进入首页
resp = s.get(url_info)
print(resp.cookies)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)
# print(resp.text)
# # 获取cookies
# cookies = resp.cookies.get_dict()


# 4.查询资产
data_search= {
    'pageNo':'1',
    'status':'2',
    'title':''
}
resp = requests.post(url_info,data=data_search,cookies=cookies)
# print(resp.text)


# 5.新增资产
title = '海尔空调'
storageId = '辽宁异界公司'
providerId = '电脑设备库'
data_add = {
    'title': title,
    'storageId': storageId,
    'providerId': providerId
}
resp = s.post(url_add,data=data_add)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)
# 6. 资产修改
asset_id = {'id': '1963'}
s.get(url_mod, params=asset_id)
mod_title = {
    'title': '这是一次友好的修改',
    'storageId': '维信科技发展有限公司',
    'providerId': '会计部'
}
resp = s.post(url_mod, data=mod_title)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 7.资产借用页
data_borrow_id = {'id': '1963'}
resp = s.get(url_borrow_page,params=data_borrow_id)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 8.资产借用
data_borrow = {
    'id': '1963',
    'departId': '会计部',
    'remark': '1',
}
resp = s.post(url_borrow_page,data=data_borrow)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 9.资产归还页
asset_id = {'id': '1963'}
resp = s.get(url_return_page,params=asset_id)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)
# 10.资产归还
asset_id = {'id': '1963'}
resp = s.post(url_return,data=asset_id)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 11.查询存放地点
resp = s.post(url_storage)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 12.查询存供应商
resp = s.post(url_provider)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 13.个人信息页
resp = s.get(url_information)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)


